//
//  AdvancedCourse.m
//  Courses
//
//  Created by xxx on 15/1/9.
//  Copyright (c) 2015年 wtf. All rights reserved.
//

#import "AdvancedCourse.h"
#import "Request.h"
#import "CourseClass.h"

@implementation AdvancedCourse

- (id)initWithJsonDict:(NSDictionary *)jsonDict
{
    if (self = [super initWithJsonDict:jsonDict])
    {
        self.TeacherdescShort = jsonDict[@"teacherDescShort"];
        self.lessonHours = jsonDict[@"lessonHours"];
        self.courseClasses = [[NSMutableArray alloc] init];
        for (id dict in jsonDict[@"classes"])
        {
            if ([dict isKindOfClass:[NSDictionary class]])
            {
                CourseClass *courseClass = [[CourseClass alloc] initWithJsonDict:dict];
                [self.courseClasses addObject:courseClass];
            }
        }
        self.selectedClsIndex = 1;
    }
    return self;
}

+ (NSArray *)getVipCourses
{
    Request *request = [Request requestWithName:@"get_vip_courses"];
    Response *response = [request response];
    
    NSMutableArray *courses = [[NSMutableArray alloc] init];
    
    if (response.result)
    {
        for (id jsonDict in response.content[@"courses"])
        {
            if ([jsonDict isKindOfClass:[NSDictionary class]])
            {
                AdvancedCourse *course = [[self alloc] initWithJsonDict:jsonDict];
                [courses addObject:course];
            }
        }
    }
    
    return [courses copy];
}
+ (NSArray* )getVipCoursesWithSortOption:(NSInteger )sortOption
                               teacherId:(NSString* )teacherId
                                   tagId:(NSString* )tagId
                                  pageNo:(NSInteger )pageNo{
    NSMutableArray *courses = [[NSMutableArray alloc] init];
    
    Request *request = [Request requestWithName:@"get_vip_courses"];
    request.body[@"sort"] = [NSNumber numberWithInt:(int)sortOption];
    
    NSMutableDictionary* condition = [[NSMutableDictionary alloc]init];
    if (teacherId.length) {
        NSMutableArray* teachers = [[NSMutableArray alloc] init];
        condition[@"teachers"] = teachers;
        NSMutableDictionary* teachId = [[NSMutableDictionary alloc] init];
        teachId[@"teacherId"] = teacherId;
        teachers[0] = teachId;
    }
    if (tagId.length) {
        condition[@"tagId"] = tagId;
    }
    request.body[@"condition"] = condition;
    
    NSMutableDictionary* page = [[NSMutableDictionary alloc]init];
    page[@"pageNo"] = [NSNumber numberWithInt:(int)pageNo];
    page[@"pageSize"] = [NSNumber numberWithInt:20];
    request.body[@"page"] = page;
    Response *response = [request response];
    
    if (!response.result) {
        return [courses copy];
    }
    
    if (response.result)
    {
        for (id jsonDict in response.content[@"courses"])
        {
            if ([jsonDict isKindOfClass:[NSDictionary class]])
            {
                AdvancedCourse *course = [[self alloc] initWithJsonDict:jsonDict];
                [courses addObject:course];
            }
        }
    }
    
    return [courses copy];
}
@end
